var students = JSON.parse(localStorage.getItem('students'));
var userId = searchToObj(location.search).userId;
function searchToObj(str) {
  var newStr = str.substr(1);
  var strArr = newStr.split('&'); 
  var obj = {};
  for (var i = 0; i < strArr.length; i++) {
    var o = strArr[i].split('=');
    obj[o[0]] = o[1];
  }
  return obj;
}

var user = students.find(function (item) {
    return item.id == userId;
  });

$('#ly_val1').val(user.name);
$('#ly_val2').val(user.class);
$('#ly_val3').val(user.gender);
$('#ly_val4').val(user.parentname);
$('#ly_val5').val(user.parentphone);
$('#ly_val6').val(user.years);
$('#ly_val7').val(user.phone);
$('#ly_val8').val(user.Email);
$('#ly_val9').val(user.address);
$('#ly_val10').val(user.Dates);
$('#ly_val11').val(user.hobby);
$('#ly_val12').val(user.introduce);
$('#ly_val13').val(user.Awards);


$('.p1').on('click',function() {
  students.forEach(function(item) {
    if(item.id == user.id) {
      item.name = $('#ly_val1').val();
      item.class = $('#ly_val2').val();
      item.gender = $('#ly_val3').val();
      item.parentname = $('#ly_val4').val();
      item.parentphone = $('#ly_val5').val();
      item.years = $('#ly_val6').val();
      item.phone = $('#ly_val7').val();
      item.Email = $('#ly_val8').val();
      item.address = $('#ly_val9').val();
      item.Dates = $('#ly_val10').val();
      item.hobby = $('#ly_val11').val();
      item.introduce = $('#ly_val12').val();
      item.Awards = $('#ly_val13').val();
    }
  })
  localStorage.setItem('students', JSON.stringify(students));
  $('#ly_val1').val('');
  $('#ly_val2').val('');
  $('#ly_val3').val('');
  $('#ly_val4').val('');
  $('#ly_val5').val('');
  $('#ly_val6').val('');
  $('#ly_val7').val('');
  $('#ly_val8').val('');
  $('#ly_val9').val('');
  $('#ly_val10').val('');
  $('#ly_val11').val('');
  $('#ly_val12').val('');
  $('#ly_val13').val('');
  parent.layer.msg('提交成功',{icon: 6}); 
  console.log(students) 
})
